<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h1>最高级：{{ num }}</h1>
        <Child></Child>

    </div>
    <script src="./js/vue.js"></script>
    <script id="child" type="text/x-template">
    <div>
        <h2>中级</h2>
     <grandson></grandson>
    </div>
    </script>

    <script>
        const eventBus = new Vue()

        const grandson = {
            template: `<div>
        <h3>子孙</h3>
        <hr/>
        <button @click="ccc">自增</button>
      </div>`,
            methods: {
                ccc() {
                    eventBus.$emit('incrnum', 10)
                }
            }
        }
        const Child = {
            template: '#child',
            components: { grandson }
        }



        const app = new Vue({
            el: '#app',
            data: {
                num: 2
            },
            created() {
                // 订阅
                eventBus.$on('incrnum', n => {
                    this.num += n
                })
            },
            components: { Child },
            mathods: {

            }

        })
    </script>
</body>

</html>